package com.fowo.api.sys.service.impl;

import com.fowo.api.sys.service.ThumbnailService;
import net.coobird.thumbnailator.Thumbnails;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

@Service
public class ThumbnailServiceImpl implements ThumbnailService {
    @Override
    public void createThumbnail(int maxWidth, int maxHeight,
                                InputStream inputStream,
                                OutputStream outputStream
    ) throws UnsupportedOperationException, IOException {
        Thumbnails.of(inputStream)
                .size(maxWidth, maxHeight)
                .outputFormat("jpg")
                .toOutputStream(outputStream);
    }
}
